// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (a%=p; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}

const int N = 1e5+50;
const int MOD = 1e9;

// char s[N];
int n;

map<char, pair<LL, LL>> mp;

pair<LL, LL> operator + (const pair<LL, LL> &a, const pair<LL, LL> &b) {
	auto c = a;
	c.first = (c.first + b.first + MOD) % MOD;
	c.second = (c.second + b.second + MOD) % MOD;
	return c;
}

pair<LL, LL> dfs() {

	pair<LL, LL> res(0, 0);
	// for (char nc=getchar(); !isdigit(nc); nc=getchar()) {
	// 	res = res + mp[nc];
	// }

	for (char nc=getchar(); nc!=')' && nc!='\n'; nc=getchar()) {
		pair<LL, LL> del;
		if (isdigit(nc)) {
			LL t = nc-'0';
			getchar();
			auto res = dfs();
			del.first = res.first * t % MOD;
			del.second = res.second * t % MOD;
		} else {
			del = mp[nc];

		}
		// dbg(del.first, del.second);
		res = res + del;
		// dbg(res.first, res.second);
	}
	// dbg(res.first, res.second);
	return res;
}

int main(int argc, char const *argv[]) {
    // code
	mp['S'] = pair<LL, LL>(1, 0);
	mp['N'] = pair<LL, LL>(-1, 0);
	mp['W'] = pair<LL, LL>(0, -1);
	mp['E'] = pair<LL, LL>(0, 1);

    int t;
    scanf("%d", &t); getchar();
    for (int kk=0; kk<t; ++kk) {
    	printf("Case #%d: ", kk+1);
    	auto res = dfs();
    	printf("%lld %lld\n", res.second+1, res.first+1);

    }
    return 0;
}